package com.lwc.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lwc.service.impl.StockImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class GoodsController {

    @Autowired
    StockImpl stock;

    @SentinelResource(value = "查看商品",fallback = "fallback")
    @GetMapping("/getgoods")
    public Map getgoods(){
        Map map=new HashMap<>();
        map.put("goodsname","西瓜");
        map.put("num",stock.queryStock());
        return  map;
    }

    public Map fallback(){
        Map  map=new HashMap<>();
        map.put("code",2000);
        map.put("nsg","错误");
        return  map;
    }

}
